<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2022/5/9
 * Time: 12:49
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

namespace app\common\business;

use app\common\model\MallSearchUser;
use think\Exception;

class BusSearchUser extends Base
{
    protected $model = null;

    public function __construct()
    {
        $this->model = new MallSearchUser();
    }

    /**
     * 删除所有
     * @param array $where
     * @param bool $delete
     * @return bool
     * @throws Exception
     */
    public function setDeleteAll(array $where = [], bool $delete = false)
    {
        $ids = [];

        try {
            $row = $this->model->getBaseByListAll($where, 'id');
        } catch (\Exception $e) {
            throw new Exception("删除失败");
        }
        if(empty($row)){
            throw new Exception("没有可以删除的");
        }
        try {
            $result = $this->model->destroy(array_column($row, 'id'), $delete);
        } catch (\Exception $e) {
            throw new Exception("删除失败");
        }
        if ($result) {
            return true;
        } else {
            return false;
        }
    }
}